<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>我的任务申请</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
    <div th:replace="~{fragments/header :: header}"></div>
    
    <div class="container mt-4">
        <h2>我的任务申请</h2>
        
        <div th:if="${applications.empty}" class="alert alert-info">
            您还没有申请任何任务
        </div>
        
        <div th:if="${!applications.empty}">
            <div class="row">
                <div class="col-12">
                    <div class="table-responsive">
                        <table class="table table-striped table-hover">
                            <thead>
                                <tr>
                                    <th>申请ID</th>
                                    <th>任务ID</th>
                                    <th>任务名称</th>
                                    <th>申请时间</th>
                                    <th>交付状态</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr th:each="app : ${applications}">
                                    <td th:text="${app.applicationId}">申请ID</td>
                                    <td th:text="${app.taskId}">任务ID</td>
                                    <td>
                                        <a th:href="@{/freelancer/tasks/{id}(id=${app.taskId})}" 
                                           th:text="${taskMap.get(app.applicationId)?.title ?: '未知任务'}">
                                            任务名称
                                        </a>
                                    </td>
                                    <td th:text="${#temporals.format(app.applyTime, 'yyyy-MM-dd HH:mm')}">申请时间</td>
                                    <td>
                                        <span th:if="${app.deliveryStatus == 'not_delivered'}" class="badge bg-primary">未交付</span>
                                        <span th:if="${app.deliveryStatus == 'delivered'}" class="badge bg-warning">已交付</span>
                                        <span th:if="${app.deliveryStatus == 'confirmed'}" class="badge bg-success">已确认</span>
                                    </td>
                                    <td>
                                        <a th:href="@{/freelancer/tasks/{id}(id=${app.taskId})}" class="btn btn-sm btn-primary">查看详情</a>
                                        <a th:href="@{/freelancer/task-applications/{id}(id=${app.applicationId})}" class="btn btn-sm btn-success" th:if="${app.deliveryStatus == 'not_delivered'}">提交成果物</a>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <div th:replace="~{fragments/footer :: footer}"></div>
</body>
</html>